package com.maixun.lib_business_home.home

import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.maixun.lib_base.utils.LogUtils
import com.maixun.lib_business_home.R
import com.maixun.lib_business_home.entity.BannerBeen
import com.maixun.lib_business_home.entity.HomeDataBeen
import com.maixun.lib_business_home.entity.HomeHeadBeen
import com.maixun.lib_comment.ARouterConstance
import com.maixun.lib_comment.ui.BaseMVPFragment
import com.youth.banner.indicator.RectangleIndicator
import com.youth.banner.util.BannerUtils
import kotlinx.android.synthetic.main.home_fragment_home.*

/**
 * @author：Lmoumou
 * @date：2020/10/14
 */
@Route(path = ARouterConstance.HOME.URL_HOME_MAIN)
class HomeFragment : BaseMVPFragment<HomePresenterImpl>(), HomeContract.View {

    override val mPresenter: HomePresenterImpl by lazy { HomePresenterImpl(this) }
    override fun getLayoutId(): Int = R.layout.home_fragment_home

    override fun isLazyLoad(): Boolean = true

    override fun loadData() {
        LogUtils.e("HomeFragment", "loadData")
    }

    private val bannerList by lazy { mutableListOf<BannerBeen>() }
    private val bannerAdapter by lazy { ImageBannerAdapter(mContext, bannerList) }

    private val dataList by lazy { mutableListOf<Any>() }
    private val adapter by lazy { HomeAdapter(mContext, dataList) }
    override fun initView(rootView: View, savedInstanceState: Bundle?) {
        initHeadUI()

        dataList.add(HomeHeadBeen("精彩回放", iconResId = R.mipmap.home_title_replay))
        dataList.add(HomeDataBeen.HomeVideoBeen())
        dataList.add(HomeDataBeen.HomeVideoBeen())
        dataList.add(HomeDataBeen.HomeVideoBeen())
        dataList.add(HomeHeadBeen("精选课程", iconResId = R.mipmap.home_title_course))
        dataList.add(HomeDataBeen.HomeVideoBeen())
        dataList.add(HomeDataBeen.HomeVideoBeen())
        dataList.add(HomeDataBeen.HomeVideoBeen())
        dataList.add(HomeHeadBeen("超声文献", iconResId = R.mipmap.home_title_literature))
        dataList.add(HomeDataBeen.HomeLiteratureBeen())
        dataList.add(HomeDataBeen.HomeLiteratureBeen())
        dataList.add(HomeDataBeen.HomeLiteratureBeen())
        dataList.add(HomeHeadBeen("专家大咖", iconResId = R.mipmap.home_title_expert))
        dataList.add(HomeDataBeen.HomeExpertBeen())
        dataList.add(HomeDataBeen.HomeExpertBeen())
        dataList.add(HomeDataBeen.HomeExpertBeen())
        mRecyclerView.adapter = adapter
    }

    private fun initHeadUI() {
        bannerList.add(BannerBeen("https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00089-4094.jpg"))
        bannerList.add(BannerBeen("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1605971078,3388219182&fm=26&gp=0.jpg"))

        mBanner.adapter = bannerAdapter
        mBanner.addBannerLifecycleObserver(this)
        mBanner.indicator = RectangleIndicator(mContext)
        mBanner.setIndicatorSelectedColor(Color.WHITE)
        mBanner.setIndicatorNormalColor(Color.parseColor("#80FFFFFF"))
        mBanner.setIndicatorWidth(BannerUtils.dp2px(12F).toInt(), BannerUtils.dp2px(24F).toInt())
        mBanner.setIndicatorRadius(BannerUtils.dp2px(3F).toInt())
        mBanner.setIndicatorHeight(BannerUtils.dp2px(6F).toInt())
        mBanner.setIndicatorSpace(BannerUtils.dp2px(12F).toInt())
    }


}